#include "jabberidtest.h"
#include "xmppcore/jabberid.h"

#include <QtTest/QTest>


namespace yoohoo_xmppcore {

void JabberIdTest::testFromString() {
	JabberId jabberId3;
	JabberId jabberId4;
	JabberId jabberId5;

	QString jidString1 = "node@domain";
	QString jidString2 = "node@domain/resource";
	QString jidString3 = "node@domain@resource";

	QVERIFY(jabberId3.fromString(jidString1));
	QCOMPARE(jabberId3.node(), QString("node"));
	QCOMPARE(jabberId3.domain(), QString("domain"));
	QCOMPARE(jabberId3.resource(), QString(""));

	QVERIFY(jabberId4.fromString(jidString2));
	QCOMPARE(jabberId4.node(), QString("node"));
	QCOMPARE(jabberId4.domain(), QString("domain"));
	QCOMPARE(jabberId4.resource(), QString("resource"));

	QVERIFY(!jabberId5.fromString(jidString3));
}

void JabberIdTest::testToString() {
	JabberId jabberId1;
	jabberId1.setNode("node");
	jabberId1.setDomain("domain");

	JabberId jabberId2;
	jabberId2.setNode("node");
	jabberId2.setDomain("domain");
	jabberId2.setResource("resource");

	QCOMPARE(jabberId1.toString(), QString("node@domain"));
	QCOMPARE(jabberId2.toString(), QString("node@domain/resource"));
}

}

QTEST_MAIN(yoohoo_xmppcore::JabberIdTest);
